<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
  </head>
  <body>
    <script>
      var majorityElement = function (nums) {
        let count = 1;
        let majority = nums[0];
        for (let i = 1; i < nums.length; i++) {
          if (count === 0) {
            majority = nums[i];
          }
          if (nums[i] === majority) {
            count++;
          } else {
            count--;
          }
        }
        return majority;
      };
      console.log(majorityElement([1, 1, 2, 1, 2, 1, 2, 2, 2, 2]));
    </script>
  </body>
</html>
